export * from './Toast';
export * from './Notificatorio';
import React, { useMemo, PropsWithChildren } from "react";
export type ProviderInfo<P extends PropsWithChildren = PropsWithChildren> =
  [React.FC<P>, Omit<P, 'children'>] | [React.FC<P>] | React.FC<P> | React.ReactElement<unknown>

export interface ProvidersProps extends React.PropsWithChildren {
  providers: ProviderInfo[]
}
/** FIXME: 勿用，此组件的写法不行，待修复后再说 */
export function Providers(props: ProvidersProps) {
  const { providers, children } = props;
  const wrapper = (() => {
    let element: React.ReactElement = <></>;
    for (const what of providers) {
      if (React.isValidElement(what)) {
        element = React.cloneElement(element, void 0, what)
        continue;
      }
      const [Provider, props] = Array.isArray(what) ? what : [what]
      
      element = React.cloneElement(element, void 0, <Provider {...props} />)
    }
    return element
  })()

  return React.cloneElement(wrapper, void 0, children)
}